<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="spring" 	uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" 	uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c"		uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" 	uri="http://www.springframework.org/tags/form" %>

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>


<c:url value="/reports/download" var="downloadUrl"/>
<c:url value="/reports/download/token" var="downloadTokenUrl"/>
<c:url value="/reports/download/progress" var="downloadProgressUrl"/>


<script type="text/javascript">
$(document).ready(function(){
	 $("#pdfButton").kendoButton({
         click: downloadPdf
     });
	 
	 $("#xlsButton").kendoButton({
         click: downloadXls
     });
	
});	
 
	function downloadXls() {download('xls');}
	
	function downloadPdf() {download('pdf');}
	
	function download(type) {
		// Retrieve download token
		// When token is received, proceed with download
		$.get('${downloadTokenUrl}', function(response) {
			// Store token
			var token = response.message[0];
			
			// Show progress dialog
			$("#testWindow").text('Processing download...');
			
			 $("#testWindow").kendoWindow({
		        width: "300px",
		        title: "Progress...",
				actions: ["Close"]
			 });

			// Start download
			var win=window.open('${downloadUrl}'+'?token='+token+'&type='+type , '_blank');
			  	win.focus();
 			
			// Check periodically if download has started
			var frequency = 1000;
			var timer = setInterval(function() {
				$.get('${downloadProgressUrl}', {token: token}, 
						function(response) {
							// If token is not returned, download has started
							// Close progress dialog if started
							if (response.message[0] != token) {
								//$('#msgbox').dialog('close');
								$("#testWindow").data("kendoWindow").close();
								clearInterval(timer);
							}
					});
			}, frequency);
			
		});
	}
	
	

</script>
	<div id="msgbox" title="" style="display:none;"> </div>

 	<div id="testWindow"></div>
 	
 
	<HR />
	<BR />
	<H4>Report Tester H1</H4>
	<BR />			
	<HR />
	<button type="button" id="pdfButton">PDF</button>
	<button type="button" id="xlsButton">XLS</button>

		
	    				
